﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProgNetComponents.Design.Editors;
using ProgNetComponents.Utils;

namespace ProgNetComponents.Validation.Design
{
    public class IDataValidationRuleColumnNameEditor : ColumnNameEditor
    {
        protected override bool FillCollection(Collections.NamedObjectCollection collection, System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context.Instance is IDataValidationRule)
            {
                object dataSource = ((IDataValidationRule)context.Instance).DataSource;
                var columns = DesignUtils.GetColumns(dataSource, null, context, provider);
                foreach (var col in columns)
                    collection.Add(col, col);
            }
            else
            {
                base.FillCollection(collection, context, provider, value);
            }
            return true;
        }
    }
}
